import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:winkai/ui/discover/discover_page.dart';
import 'package:winkai/ui/msg/msg_page.dart';
import 'package:winkai/ui/root/widget/root_title_widget.dart';
import 'package:winkai/widget/keep_alive.dart';

import 'root/controller/root_controller.dart';

class RootPage extends StatefulWidget {
  const RootPage({super.key});

  @override
  State<RootPage> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage>
    with SingleTickerProviderStateMixin {
  final controller = Get.put(RootController());

  @override
  void initState() {
    super.initState();
    controller.pages = [
      keepAliveWrapper(const DiscoverPage()),
      keepAliveWrapper(const MsgPage()),
    ];
    controller.tabController = TabController(
        initialIndex: controller.currentIndex,
        length: controller.pages.length,
        vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.dark,
        child: Column(
          children: [
            const RootTitleWidget(),
            Expanded(
              child: TabBarView(
                controller: controller.tabController,
                children: controller.pages,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
